package com.fafa.File;

import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class FileMKDir {
    public static void main(String[] args) {

    }

    @Test
    public void mkdir() {
        File filePath = new File("E:\\news1.txt");
        if (filePath.exists()) {
            if ( filePath.delete()) {
                System.out.println("删除成功");
            }
        } else {
            System.out.println("文件不存在");
            try {
                filePath.createNewFile();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }


    @Test
    public void mkdir2() {
        File filePath = new File("E:\\news2");
        if (filePath.exists()) {
            System.out.println("目录存在");
            if(filePath.delete())
            {
                System.out.println("删除成功");
            }
        } else {
            System.out.println("目录不存在");
            filePath.mkdir();
        }
    }
}
